#ifndef MOVEBUTTON_H
#define MOVEBUTTON_H
#include <QPushButton>
#include <QMouseEvent>
#include <QEvent>
#include <QWidget>

class MoveButton : public QPushButton
{
    Q_OBJECT
public:
    MoveButton(QWidget* parent);

    /**
     * @brief setDirection      设置停靠方向
     * @param value
     */
    void setDirection(int value);

    /**
     * @brief changePos         当坐标改变的时候，重新计算位置
     */
    void changePos();

    /**
     * @brief moveEnabled       是否可移动
     * @return
     */
    bool moveEnabled() const;
    void setMoveEnable(bool value);

protected:
    void mousePressEvent(QMouseEvent *e);
    void mouseMoveEvent(QMouseEvent* e);
    void mouseReleaseEvent(QMouseEvent* e);

signals:
    void moved();
    void docked(int);
private:
    QWidget *parent;
    bool pressed;
    bool alreadyMove;
    QPoint pressPoint;
    bool moveEnable;
    int direction;      //0:中间 1：上 2：下 3：左 4：右

};

#endif // MOVEBUTTON_H
